package com.github.wujichen158.andemusic.playernbt;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;

public class MusicTypeStorage implements Capability.IStorage<IMusicCapability> {
    public static final MusicTypeStorage INSTANCE = new MusicTypeStorage();
    public static final String MUSIC_TYPE = "MusicType";
    public static final String MAX_DELAY_TIME = "MaxDelayTime";
    public static final String MIN_DELAY_TIME = "MinDelayTime";

    public MusicTypeStorage() {
    }

    @Override
    public NBTBase writeNBT(Capability<IMusicCapability> capability, IMusicCapability instance, EnumFacing side) {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setString(MUSIC_TYPE, instance.getMusicType());
        compound.setInteger(MIN_DELAY_TIME, instance.getMinDelayTime());
        compound.setInteger(MAX_DELAY_TIME, instance.getMaxDelayTime());
        return compound;
    }

    @Override
    public void readNBT(Capability<IMusicCapability> capability, IMusicCapability instance, EnumFacing side, NBTBase nbt) {
        NBTTagCompound compound = (NBTTagCompound) nbt;
        instance.setMusicType(compound.getString(MUSIC_TYPE));
        instance.setMinDelayTime(compound.getInteger(MIN_DELAY_TIME));
        instance.setMaxDelayTime(compound.getInteger(MAX_DELAY_TIME));
    }
}
